package com.test.order;

import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;

/**
 * @author 魏彪
 */
@Component
@WithStateMachine(name = "orderStateMachine")
public class OrderStateListener {

    @OnTransition(source = "WAIT_PAYMENT", target = "WAIT_DELIVER")
    public boolean payTransition(Message<Order> message) {
        Order order = message.getPayload();
        System.out.println("order = " + order);
        return true;
    }

    @OnTransition(source = "WAIT_DELIVER", target = "WAIT_RECEIVE")
    public boolean deliverTransition(Message<Order> message) {
        Order order = message.getPayload();
        System.out.println("order = " + order);
        return true;
    }

    @OnTransition(source = "WAIT_RECEIVE", target = "FINISH")
    public boolean finishTransition(Message<Order> message) {
        Order order = message.getPayload();
        System.out.println("order = " + order);
        return true;
    }
}
